package com.ysd.lis.service.qi.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.qi.QiMajorBusiness;
import com.ysd.lis.mapper.qi.QiMajorBusinessMapper;
import com.ysd.lis.service.qi.QiMajorBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 质量指标-专业对照表 服务实现类
 * </p>
 *
 * @author wh
 * @since 2025-03-04
 */
@Service
public class QiMajorBusinessServiceImpl extends ServiceImpl<QiMajorBusinessMapper, QiMajorBusiness> implements QiMajorBusinessService {

    @Autowired
    private QiMajorBusinessMapper qiMajorBusinessMapper;

    @Override
    public Result findQiMajorBusinessList(QiMajorBusiness qiMajorBusiness) {
        MPJLambdaWrapper<QiMajorBusiness> mpjLambdaWrapper = new MPJLambdaWrapper<>();
        mpjLambdaWrapper.selectAll(QiMajorBusiness.class)
                .eq(QiMajorBusiness::getDelFlag, 0)
                .eq(QiMajorBusiness::getMajorCode, qiMajorBusiness.getMajorCode())
                .eq(QiMajorBusiness::getModuleType, qiMajorBusiness.getModuleType())
                .orderByAsc(QiMajorBusiness::getCreateTime);
        List<QiMajorBusiness> list = qiMajorBusinessMapper.selectList(mpjLambdaWrapper);
        return Result.succ(list);
    }

    @Override
    public Result addQiMajorBusiness(QiMajorBusiness qiMajorBusiness) {
        boolean save = this.saveOrUpdate(qiMajorBusiness,new LambdaQueryWrapper<QiMajorBusiness>().eq(QiMajorBusiness::getMajorCode,qiMajorBusiness.getMajorCode()).eq(QiMajorBusiness::getModuleType,qiMajorBusiness.getModuleType()).eq(QiMajorBusiness::getBusinessValue,qiMajorBusiness.getBusinessValue()).eq(QiMajorBusiness::getDelFlag,0));
        if (save) {
            return Result.succ(1, "", null);
        } else {
            return Result.fail("添加失败！");
        }
    }

    @Override
    public Result deleteQiMajorBusiness(QiMajorBusiness qiMajorBusiness) {
        boolean b = this.removeById(qiMajorBusiness.getId());
        if (b) {
            return Result.succ(1, "移除成功", null);
        } else {
            return Result.fail("移除失败！");
        }
    }
}
